package com.atguigu.yygh.cmn.controller;


import com.alibaba.excel.EasyExcel;
import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 * 组织架构表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/admin/cmn")
public class DictController {


    @Autowired
    private DictService dictService;

    @GetMapping("/childList/{pid}")
    public R childList(@PathVariable Long pid){
       List<Dict> dictList= dictService.getChildListByPid(pid);
       return R.ok().data("list",dictList);
    }

    @GetMapping("download")
    public void download(HttpServletResponse response) throws Exception {
        dictService.download(response);
    }

    @PostMapping("importData")
    public void importData(MultipartFile file) throws IOException {
        dictService.importData(file);
    }

    //根据省市区编号查询对应的文字
    @GetMapping("getNameByValue/{value}")
    public String getNameByValue(@PathVariable("value") String value){
       return dictService.getNameByValue("",value);
    }

    //根据医院编号和dict_code查询医院等级信息
    @GetMapping("getNameByValue/{dictCode}/{value}")
    public String getNameByDictCodeAndValue(@PathVariable("dictCode") String dictCode,@PathVariable("value") String value){
        return dictService.getNameByValue(dictCode,value);
    }

    //
    @GetMapping("getChildrenByDictcode/{dictCode}")
    public R getChildrenByDictcode(@PathVariable("dictCode") String dictCode){
        return R.ok().data("list",dictService.getChildrenByDictcode(dictCode));
    }


}

